//////////////////////////////////////////////
//Written by KhanhHH
//22-09-2012
//////////////////////////////////////////////

#ifndef MOBILE_SERVICE_HPP
#define MOBILE_SERVICE_HPP

#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>

#include <protocol/TBinaryProtocol.h>
#include <transport/TSocket.h>
#include <transport/TTransportUtils.h>
#include <UserAgentParser.h>
#include "lru_cache_using_boost.hpp"
#include "server.hpp"

using namespace std;
using namespace boost;
namespace http {
namespace server3 {

class  mobile_service{
public:
    explicit mobile_service(string ip, int port);
    ~mobile_service();
    void init();
    bool parse_user_agent(string& input, string& output);
    std::string parse_cache(std::string input);
    bool  parse_user_agent_service(string& input, string& output);

    //store as a static variable in the case recreate luastate ==> Do no losing cached data
    typedef lru_cache_using_boost<std::string, std::string> lru_cache;
    boost::shared_ptr<lru_cache> cache_ptr;
    void set_cache(boost::shared_ptr<lru_cache> cache_ptr_);

private:
    string ip;
    int port;
    //for identifying in caching process
    static int service_count;
    int id_service;
    shared_ptr<apache::thrift::transport::TTransport> socket_ptr_;
    shared_ptr<apache::thrift::transport::TTransport> transport_ptr_;
    shared_ptr<apache::thrift::protocol::TProtocol> protocol_ptr_;
    shared_ptr<UserAgentParserClient> client_ptr_;

};
}
}
#endif // MOBILE_SERVICE_HPP
